from fastapi import FastAPI
# Uvicorn 是一个 ASGI（Asynchronous Server Gateway Interface）服务器，
# 专门用于运行异步 Python Web 应用
import uvicorn
from fastapi.middleware.cors import CORSMiddleware
from settings import TORTOISE_ORM
from tortoise.contrib.fastapi import register_tortoise
from apps.users.urls import user

app = FastAPI()

# 跨域
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许的前端地址
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 数据库
register_tortoise(
    app,
    config=TORTOISE_ORM,
    generate_schemas=True,
    add_exception_handlers=True,
)

app.include_router(user, prefix="", tags=["user"])

if __name__ == '__main__':
    uvicorn.run(app, host="127.0.0.1", port=8222)
